package com.bwie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bwie.mapper.TbDecpMapper;
import com.bwie.poi.StringUtils;
import com.bwie.pojo.TbDecp;
import com.bwie.pojo.TbPost;
import com.bwie.service.TbPostService;
import com.bwie.mapper.TbPostMapper;
import com.bwie.utils.R;
import com.bwie.vo.PageInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
* @author 叶雨洁
* @description 针对表【tb_post】的数据库操作Service实现
* @createDate 2025-08-06 09:10:56
*/
@Service
public class TbPostServiceImpl extends ServiceImpl<TbPostMapper, TbPost>
    implements TbPostService{

    @Autowired
    TbPostMapper tbPostMapper;

    @Autowired
    TbDecpMapper decpMapper;
    @Override
    public R getPostList(PageInfoVo pageInfoVo) {

        //进行分页查询
        Page<TbPost> tbPostPage = new Page<>(pageInfoVo.getPageNum(),pageInfoVo.getPageSize());
        QueryWrapper<TbPost> queryWrapper = new QueryWrapper<>();
        if(StringUtils.isNotEmpty(pageInfoVo.getKeyWord())){

         queryWrapper.lambda().like(TbPost::getCarCode,pageInfoVo.getKeyWord());
        }
        if(pageInfoVo.getBeginTime()!=null ){
            queryWrapper.lambda().gt(TbPost::getJoinTime,pageInfoVo.getBeginTime());
        }
        if(pageInfoVo.getBeginTime()!=null){
            queryWrapper.lambda().lt(TbPost::getJoinTime,pageInfoVo.getEndTime());
        }
        Page<TbPost> tbPostPage1 = tbPostMapper.selectPage(tbPostPage, queryWrapper);
        return R.OK(tbPostPage1);
    }

    @Override
    public R getCount(Integer postId) {

       List<TbPost>tbPosts= tbPostMapper.getCount(postId);
        return R.OK(tbPosts);
    }

    @Override
    public R sAdd(TbPost tbPost) {

        tbPost.setCountTime("2/小时");
        tbPost.setJoinTime(new Date());
        tbPost.setCount(500);
        tbPostMapper.insert(tbPost);
        return R.OK();
    }

    @Override
    public R getPostDesp(Integer postId) {

       TbDecp decp= decpMapper.selectByPostId(postId);
        return R.OK(decp);
    }
}




